﻿@model IEnumerable<BBICMS.Model.Works.WorkType>
@{
    ViewBag.Title = "案例分类";
    ViewBag.PageTitle = ViewBag.Title + "_内容";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}



    <div class="panel panel-default">
        <header class="panel-heading">
            <span class="glyphicon glyphicon-file"></span> @ViewBag.Title
        </header>
        
        <section class="panel-body">
            <div class="text-right">
                <a class="btn btn-primary" href="@Url.Action("AddType")"><i class="glyphicon glyphicon-plus"></i> 添加分类</a>
                <a class="btn btn-default" href="@Url.Action("AddWork")"><i class="glyphicon glyphicon-plus"></i> 添加案例</a>
            </div>
        </section>

        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                       
                        <th>
                            主题
                        </th>
                        <th>
                            描述
                        </th>
                      
                        <th>
                            <span class="glyphicon glyphicon-user"></span> 发布者
                        </th>
                        <th>
                            <span class="glyphicon glyphicon-time"></span> 创建日期
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var WorkType in Model)
                    {
                        <tr class="first">
                           

                            <td>
                                @WorkType.Title
                            </td>
                            <td>
                                @WorkType.Description
                            </td>
                           
                            <td>
                                @WorkType.AddedBy
                            </td>


                            <td>@WorkType.AddedDate.ToShortDateString()</td>
                            <td>
                                <a href="@Url.Action("EditType", new { Id = WorkType.Id })" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i></a>
                                <a href="@Url.Action("DeleteType", new { Id = WorkType.Id })" class="btn btn-xs btn-danger delete-type"><i class="glyphicon glyphicon-trash"></i></a>
                            </td>
                        </tr>
                    }

                </tbody>

            </table>



        </div>


        <footer class="panel-footer">
            
        </footer>


    </div>

<!-- end main container -->
@section footer {

    <script>

        $(function () {
         


            //删除数据
            $('.delete-type').click(function (e) {
                var url = $(this).attr('href');
                var that = $(this);
               // console.log(url);
                /*DELETE*/
                $.ajax({
                    url: url,
                    dataType: "json",
                    type: "DELETE",
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify({}),
                    async: true,
                    processData: false,
                    cache: false,
                    success: function (data) {
                        if (data) {                          
                            toastr.success('案例分类已删除成功！', '删除分类');
                            that.closest('tr').remove();
                        } else {
                            toastr.error('案例分类删除失败！', '删除分类');
                        }
                    },
                    error: function (xhr) {
                        toastr.error('案例分类删除失败！', '删除分类');
                    }
                });

                e.preventDefault();
            })

        });
    </script>

}